<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 用户列表 -->
      <el-table :data="orderList" style="width: 100%;" border stripe>
        <el-table-column type="index" width="50" label="序号"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="220"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="220"></el-table-column>
        <el-table-column prop="user_id" label="用户"></el-table-column>
        <el-table-column prop="order_pay" label="是否付款"></el-table-column>
        <el-table-column prop="order_pay" label="是否付款">
          <template slot-scope="scope">{{scope.row.order_pay == 0 ? '未付款': '已付款'}}</template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>

        <el-table-column prop="create_time" label="订单创建时间">
          <template scope="scope">{{scope.row.create_time|dateFormat}}</template>
        </el-table-column>
        <el-table-column prop="create_time" label="操作">
          <template>
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
              @click="dialogVisible = true"
            >编辑</el-button>
            <el-button
              type="warn"
              size="mini"
              icon="el-icon-location"
              @click="addressDialogVisible = true"
            >物流</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="dialogVisible"
      width="30%"
      :show-close="false"
      :modal="true"
      :close-on-click-modal="false"
    >
      <el-form :model="addressForm" :rules="addressFormRules" ref="addressFormFormRef">
        <el-form-item label="省市区/县" label-width="20%" prop="address1">
          <el-cascader
            v-model="addressForm.address1"
            :options="addressList"
            expandTrigger="hover"
            :props="props"
            clearable
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" label-width="20%" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="addressDialogVisible"
      width="30%"
      :show-close="false"
      :modal="true"
      title="物流信息"
    >
      <!-- <span v-for="(item, index) in addressData" :key="index">
        {{item.time}}:{{item.context}}
        <br />
      </span>-->
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in addressData"
          :key="index"
          :timestamp="activity.time"
          :color="index == 0?'#66b1ff':''"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from '../../assets/citydata'
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      total: 0,
      dialogVisible: false,
      addressDialogVisible: false,
      addressForm: {
        address1: [],
        address2: ''
      },
      addressFormRules: {
        address1: [
          { required: true, message: '请选择省市区县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      // 设置级联选择器属性
      props: {
        label: 'label',
        value: 'value',
        children: 'children'
      },
      addressList: cityData,
      addressData: []
    }
  },
  created() {
    this.getOrderList()
    this.showExpress()
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http(`orders`, {
        params: this.queryInfo
      })
      console.log(res)
      if (res.meta.status != 200)
        return this.$message.error('错误,获取数据失败')
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    async showExpress() {
      const { data: res } = await this.$http.get(`kuaidi/804909574412544580`)
      this.addressData = res.data
      console.log(this.addressData)
    }
  }
}
</script>

<style lang="less" scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';
.el-card {
  margin-top: 20px;
}
</style>